package cn.stylefeng.guns.modular.demo.service;

import cn.stylefeng.roses.kernel.dict.api.pojo.DictTreeDto;
import cn.stylefeng.roses.kernel.dict.modular.mapper.DictMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 示例服务
 *
 * @author fengshuonan
 * @since 2021/1/24 10:58
 */
@Service
public class DemoService {
    /**
     * demo方法
     *
     * @author fengshuonan
     * @since 2021/1/24 10:58
     */
    public void demoService(){
        System.out.println("这是一个demo方法");
    }

    public static void main(String[] args) throws IOException {

        String path2="E:\\json2.json";
        File file = new File(path2); // 替换为你的Json文件路径
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line;
        StringBuilder sb = new StringBuilder();

        while ((line = br.readLine()) != null) {
            sb.append(line);
        }

        String jsonContent = sb.toString();

      /* JSONArray list = JSONObject.parseArray(jsonContent);
       int j=0;
        for(int n=0;n<list.size();n++){
            j++;
            JSONObject obj = list.getJSONObject(n);
            System.out.print("INSERT INTO `single`.`sys_dict_type`(`dict_type_id`, `dict_type_class`, `dict_type_bus_code`, `dict_type_code`, `dict_type_name`, `dict_type_name_pinyin`, `dict_type_desc`, `status_flag`, `dict_type_sort`, `version_flag`, `del_flag`, `create_time`, `create_user`, `update_time`, `update_user`) VALUES (");
            Long id = new Date().getTime()+j;
            System.out.print(id+", 1, 'TIA', '"+obj.getString("submitName"));
            System.out.print("', '"+obj.getString("title"));
            System.out.print("', NULL, NULL, 1,"+(200+n));
            System.out.println(", 0, 'N', '2024-07-17 15:06:31', 1339550467939639299, NULL, NULL);");
           JSONArray js = obj.getJSONArray("list");
            for(int m=0;m<js.size();m++){
                j++;
                JSONObject ob = js.getJSONObject(m);
                System.out.print("INSERT INTO `single`.`sys_dict`(`dict_id`, `dict_type_id`, `dict_code`, `dict_name`, `dict_name_pinyin`, `dict_encode`, `dict_short_name`, `dict_short_code`, `dict_parent_id`, `dict_pids`, `status_flag`, `dict_sort`, `version_flag`, `del_flag`, `create_time`, `create_user`, `update_time`, `update_user`) VALUES (");
                System.out.print((new Date().getTime() +j)+","+id+", '");
                System.out.print(ob.getString("val"));
                System.out.print("', '"+ob.getString("remark"));
                System.out.print("', NULL, 'TIA', NULL, '"+obj.getString("submitName")+"', -1, '[-1],', 1,"+(m+1));
                System.out.println(", 0, 'N', '2024-07-17 15:07:26', 1339550467939639299, NULL, NULL);");


            }
        }*/

        JSONArray list = JSONObject.parseArray(jsonContent);
        for(int n=0;n<list.size();n++){
            String group  = "null";

            JSONObject obj = list.getJSONObject(n);
            if(obj.getString("submitName").startsWith("TIA")){
                group = "'"+ obj.getString("submitName").substring(0,5)+"'";
            }
            System.out.print("INSERT INTO `single`.`disease_type`( `disease_name`, `disease_code`, `not_null`, `remark`, `has_table`, `del_flag`, `create_time`, `create_user`, `update_time`, `update_user`, `is_use`, `type`, `example`, `rule`, `use_type`, `order_desc`, `title`, `submit_name`,disease_group) VALUES ( " +
                    "'STK急性脑梗死（首次住院）', 'STK', '"+obj.getString("notNull")+"', '");
            String val = obj.get("hasTable")==null?" NULL":"'"+obj.getString("hasTable")+"'";
            System.out.print(obj.getString("remark")+"',"+val+", 'N', '2024-08-20 15:07:26', NULL, NULL, NULL, 'Y', '"+obj.getString("type"));
            System.out.print("', '"+obj.getString("example"));
            System.out.print("', NULL, 'input', "+(1+n));

            System.out.println(", '"+obj.getString("title")+"', '"+obj.getString("submitName")+"',"+group+");");

        }
    }
}
